package com.orange.adminapi.controller.repairProblemCategory;

import com.orange.core.pojo.BR;
import com.orange.core.pojo.R;
import com.orange.core.pojo.entity.repairProblemCategory.dto.RepairProblemCategoryDTO;
import com.orange.core.pojo.entity.repairProblemCategory.vo.RepairProblemCategoryVO;
import com.orange.core.service.repairProblemCategory.RepairProblemCategoryService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>ClassName:RepairProblemCategoryController</p>
 * <p>Description: 报修单问题分类表</p>
 * <p>Author: lwm</p>
 * <p>Date: 2025/6/6 22:19</p>
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/repairProblemCategory")
public class RepairProblemCategoryController {

    private final RepairProblemCategoryService repairProblemCategoryService;

    /**
     * 报修单问题分类列表
     *
     * @return
     */
    //@PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).REPAIR_PROBLEM_CATEGORY_LIST.permission.identifier)")
    @GetMapping("/list")
    public R<List<RepairProblemCategoryVO>> list() {
        return R.ok(repairProblemCategoryService.repairProblemCategoryList());
    }

    /**
     * 报修单问题分类表新增
     *
     * @param repairProblemCategoryDTO
     * @return
     */
    //@PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).REPAIR_PROBLEM_CATEGORY_SAVE.permission.identifier)")
    @PostMapping
    public R<Boolean> save(@RequestBody @Validated RepairProblemCategoryDTO repairProblemCategoryDTO) {
        return BR.result(repairProblemCategoryService.save(repairProblemCategoryDTO));
    }

    /**
     * 报修单问题分类表详情
     *
     * @param id
     * @return
     */
    //@PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).REPAIR_PROBLEM_CATEGORY_INFO.permission.identifier)")
    public R<RepairProblemCategoryVO> info(@PathVariable("id") Integer id) {
        return R.ok(repairProblemCategoryService.info(id));
    }

    /**
     * 报修单问题分类表修改
     *
     * @param repairProblemCategoryDTO
     * @return
     */
    //@PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).REPAIR_PROBLEM_CATEGORY_UPDATE.permission.identifier)")
    @PutMapping
    public R<Boolean> update(@RequestBody @Validated RepairProblemCategoryDTO repairProblemCategoryDTO) {
        return BR.result(repairProblemCategoryService.update(repairProblemCategoryDTO));
    }

    /**
     * 报修单问题分类表批量删除
     *
     * @param ids
     * @return
     */
    //@PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).REPAIR_PROBLEM_CATEGORY_DELETE.permission.identifier)")
    @DeleteMapping("/{ids}")
    public R<Boolean> delete(@PathVariable("ids") Integer[] ids) {
        return BR.result(repairProblemCategoryService.deleteRepairProblemCategoryByIds(ids));
    }
}
